package com.xh.petdogexpert.base.tool.controller;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qiniu.QiNiuUpload;
import com.xh.petdogexpert.base.ResponseData;
import com.xh.petdogexpert.user.dto.User;

@Controller
public class UploadController {

	@Autowired
	QiNiuUpload qiniuUpload;

	@Autowired
	HttpSession session;

	@ResponseBody
	@RequestMapping(value = "qiniu/getUpLoadToken")
	public ResponseData qiniuUpload(String fileName) {
		User user = (User) session.getAttribute("user");

		if (fileName == null)
			fileName = user.getId() + "" + new Date().getTime();
		
		return new ResponseData(qiniuUpload.getUpToken(fileName));
	}

}
